import 'package:flutter_my_web/pages/tools/drop_draw_board/base/DropBean.dart';
import 'package:flutter_my_web/pages/tools/drop_draw_board/base/base_drop_widget.dart';
import 'package:flutter_my_web/pages/tools/drop_draw_board/drop_widget/drop_widget_text.dart';
//控件
enum DropType{
  base,//基础类型
  banner,//轮播
  text,//文本
  image,//图片
  list,//列表
  grid,//网格
  design,//自定义设计
}
Map<DropType,String> dropTypeMap={
  DropType.base:"base",
  DropType.banner:"banner",
  DropType.text:"text",
  DropType.image:"image",
  DropType.list:"list",
  DropType.grid:"grid",
  DropType.design:"design",
};
DropType getDropTypeByStr(String str){
  var ret = DropType.base;
  dropTypeMap.forEach((key, value) {
    if(value == str){
      ret = key;
      return;
    }
  });
  return ret;
}
extension DropTypeExt on DropType {
  String toStr(){
    var ret="base";
    dropTypeMap.forEach((key, value) {
      if(key ==this){
        ret = value;
        return;
      }
    });
    return ret;
  }
}


DropBean getDropBean(json){
  var ret=DropBean();
  var type = getDropTypeByStr(json['type']);
  if(type == DropType.text){
    ret = DropBeanText.fromJson(json);
  }else {
    ret= DropBean.fromJson(json);
  }

  return ret;
}

BaseDropWidget? buildBaseDropWidgetByType(DropBean bean) {
  if (bean is DropBeanText) {
    return DropWidgetText(DropBeanText.fromJson(bean.toJson()));
  }
  return null;
}


